﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QQ.Observer.Q1
{
    public class Investor
    {
        private string _name;

        public Investor(string name)
        {
            this._name = name;
        }

        public void SendData(Microsoft ms)
        {
            Console.WriteLine("Notified {0} of {1}'s change to {2:c}", this._name, ms.Symbol, ms.Price);

        }
    }
    public class Microsoft
    {
        private Investor _investor;
        string _symbol;
        double _price;

        public void Update()
        {
            _investor.SendData(this);

        }

        public Investor Investor
        {
            get { return _investor; }
            set { _investor = value; }
        }

        public string Symbol
        {
            get { return _symbol; }
            set { _symbol = value; }
        }

        public double Price
        {
            get { return _price; }
            set { _price = value; }
        }
    }

    public class Q1Main
    {
        public static void QMain()
        {
            var investor = new Investor("Jom");
            var ms = new Microsoft();
            ms.Investor = investor;
            ms.Symbol = "Microsoft";
            ms.Price = 120.00;
            ms.Update();

            ms.Price = 136.00;
            ms.Update();

            Console.ReadKey();

        }
    }
}
